// 导入 express
const express = require('express')
// 创建路由对象 
const router = express.Router()

// 导入验证数据的中间件
const expressJoi = require('../middleware/express-joi')

// 导入vip的路由处理函数模块
const vip_handler = require('../router_handler/vip')
// 1. 获取vip用户的列表数据
router.post('/list', vip_handler.getVipLists)

// 转手机号
let typeStr = (req, res, next) => {
    req.body.phone = String(req.body.phone)
    next()
}
let typeNum = (req, res, next) => {
    req.body.phone = Number(req.body.phone)
    next()
}

// 导入vip的验证模块
const { add_vip_schema } = require('../schema/vip')
// 2. 新增vip的路由
router.post('/add',typeStr, expressJoi(add_vip_schema), typeNum, vip_handler.addVipLists)

// 导入删除分类的验证规则对象
const { delete_vip_schema } = require('../schema/vip')
// 3. 删除vip的路由
router.get('/delete/:id', expressJoi(delete_vip_schema), vip_handler.deleteVipById)

// 导入更新vip的验证规则对象
const { update_vip_schema } = require('../schema/vip')
// 5. 更新vip的路由
router.post('/update', typeStr, expressJoi(update_vip_schema), typeNum, vip_handler.updateVipById)

// 向外共享路由对象
module.exports = router